package com.zb.controller;
import com.zb.entity.Score;
import com.zb.util.PageUtil;
import com.zb.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;


@Controller
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @RequestMapping("/search")
    @ResponseBody
    public PageUtil<Score> searchScore(@RequestParam Map<String,Object> param ,
                                                                @RequestParam(required = true, defaultValue = "1") Integer index)throws Exception {
        int size = 2;
        PageUtil<Score> scorePage  = scoreService.queryScorePageByMap(param, index, size);
        return scorePage;
    }


    @RequestMapping("/getScoreById")
    @ResponseBody
    public Score getScoreById(Long id){

        Score score=null;
        try {
            score=scoreService.getScoreById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return score;
    }

    @RequestMapping("/batchRemoveScore")
    @ResponseBody
    public Integer batchRemoveScore(String ids){
        Integer flag=0;
        try {
            flag=scoreService.qdtxBatchDeleteScore(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/removeScoreById")
    @ResponseBody
    public Integer removeScoreById(Long id){
        Integer flag=0;
        try {
            flag=scoreService.qdtxDeleteScoreById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
}
